﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using TinyIoC;
using WinDataInspector.Component;
using WinDataInspector.Interfaces;
using WinLogAnalyzer.Naming;

namespace WinDataInspector
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var container = TinyIoCContainer.Current;

            //Service.DataInspector dataInspector;

            container.Register<DataInspector.DataInspector>((c, n) =>
            {
                string filename = n.ContainsKey("filename") ? (string)n["filename"] : null;
                Stream stream = n.ContainsKey("stream") ? (Stream)n["stream"] : null;

                dynamic input = (String.IsNullOrEmpty(filename)) ? stream : input = filename;

                return new DataInspector.DataInspector(input);

            }, ContainerNSR.DATA_INSPECTOR);

            container.Register<IDialogFileService>((c, n) =>
            {
                DialogFileService service = new DialogFileService();
                service.Filter = "All files (*.*)|*.*";

                return service;

            }, ContainerNSR.DLG_OPEN_LOG_FILE);
        }

        private void Application_Exit(object sender, ExitEventArgs e)
        {
            Settings.ViewSettings viewSettings = Settings.ViewSettingsLocator.Instance;

            viewSettings.Save();
        }
    }
}
